//
//  BNRItemsViewController.m
//  Homepwner
//
//  Created by 赵小燕 on 16/12/25.
//  Copyright © 2016年 xiaoyanzhao. All rights reserved.
//

#import "BNRItemsViewController.h"
#import "BNRItemStore.h"
#import "BNRItem.h"
#import "HeaderView.h"

@interface BNRItemsViewController ()

@property (strong, nonatomic) BNRItem *item;
@property (nonatomic, strong) HeaderView *headerView;

@end
@implementation BNRItemsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    self.headerView = [[HeaderView alloc] initWithFrame:CGRectMake(0, 0, 375, 60)];
    UIView *header = self.headerView;
    self.tableView.tableHeaderView = header;
}

- (instancetype)init {
    self = [super initWithStyle:UITableViewStylePlain];
    if (self) {
//        NSMutableArray *items = [[NSMutableArray alloc] init];
//        for (int i = 0; i< 10; i++) {
//            BNRItem *item = [BNRItem randomItem];
//            [items addObject:item];
//        }
//        for (BNRItem *item in items) {
//            NSLog(@"%@", item);
//        }
//        items = nil;
        
        for (int i = 0; i < 5; i++) {
            [[BNRItemStore sharedStore] createItem];
        }
        
    }
    
    return self;
}

- (instancetype)initWithStyle:(UITableViewStyle)style {
//    self = [super initWithStyle:style];
//    if (self) {
//        
//    } else {
//        self = [super initWithStyle:style];
//        
//    }
    return [self init];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    return [self init];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    return [self init];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[[BNRItemStore sharedStore] allItems] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
    
//    static NSString *CellIdentifier = @"Cell";
//    
//    UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:CellIdentifier];
//    if (cell == )
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    NSArray *items = [[BNRItemStore sharedStore] allItems];
    BNRItem *item = items[indexPath.row];
    cell.textLabel.text = [item description];
    return cell;
}

@end
